package thread.system12306;

public class Window extends Thread {
    private String windowName;

    public Window(String name){
        this.windowName = name;
    }

    @Override
    //牛逼写法
    public  void run() {
//        synchronized (this){
//            sellTicket();
//        }
        sellTicket();
    }
//    垃圾写法
//    public synchronized void run() {
//            sellTicket();
//    }

    public void  sellTicket(){
        while (true){
            System12306 sys = System12306.getInstance();

            Ticket ticket = sys.getTicket();

            if (ticket == null){
                System.out.println("对不起" + windowName + "票已卖完");
                break;
            }
            System.out.println("从" + windowName + "卖出" + ticket);
        }
    }
}
